#include "scripting.h"
#include "graphics.h"

using namespace WtfGraphics;
using namespace boost::python;
using namespace WtfEngine;

/**
 * Helper class for exporting settings
 **/
template <class tSetting, class tSettingValue = typename tSetting::tType>
class ScriptSetting {
	typedef typename Meta::ValueTraits<tSettingValue>::tStorage tValue;
	typedef typename Meta::ValueTraits<tSettingValue>::tConstRef tValueRef;
	typedef typename ScriptSettingWrapper<tSetting> tWrapper;

public:
	static void Export( const String& sName )
	{
		class_<tSetting, typename tSetting::tRef, bases<WtfEngine::IDataObject>, boost::noncopyable>((sName + "Setting").c_str(),
				init< const String&, tValueRef >())
			.def_readwrite("value", &tSetting::Value)
			.def("BindNotify", &tSetting::BindNotify)
			.def("UnbindNotify", &tSetting::UnbindNotify)
		;
		implicitly_convertible<typename tSetting::tRef, WtfEngine::IDataObject::tCacheRef>();

		class_<tWrapper>(sName.c_str(), init<const String&>())
			.add_property("value", &tWrapper::Get<tValue>, &tWrapper::operator =<tValue>)
			.def("BindNotify", &tWrapper::BindNotify)
			.def("UnbindNotify", &tWrapper::UnbindNotify)
			.def("Set", &tWrapper::Set<tValue>)
			.staticmethod("Set")
		;
		implicitly_convertible<tWrapper, typename tSetting::tRef>();
	}
};

void WtfGraphics::InitScripting()
{
	class_<GraphicsMode>("GraphicsModeValue")
		.def_readwrite("hwAcceleration", &GraphicsMode::bHwAccel)
		.def_readwrite("wndStyle", &GraphicsMode::WindowStyle)
		.def_readwrite("resolution", &GraphicsMode::Resolution)
		.def_readwrite("bpp", &GraphicsMode::uBitsPerPixel)
		.def_readwrite("buffers", &GraphicsMode::uNumBuffers)
	;

	enum_<GraphicsMode::tWindowStyle>("WndStyle")
		.value("Sizable", GraphicsMode::RESIZABLE)
		.value("Fixed", GraphicsMode::FIXED)
		.value("Fullscreen", GraphicsMode::FULLSCREEN)
		.value("Borderless", GraphicsMode::BORDERLESS)
	;

	ScriptSetting<tGraphicsMode>::Export("GraphicsMode");

};
